#include<iostream>
#include<assert.h>
#include<vector>
#include<string>
#include"sqlite.hpp"

struct stu
{
    int id;
    std::string name;
    int age;
};


//  int(*callback)(void*,int,char**,char**)
int StuCallback(void* arg,int col,char** result,char** field_name){
    std::vector<stu> * arry = static_cast<std::vector<stu>*>(arg);
    stu tmpstu;
    tmpstu.id =  (int)std::stoi(result[0]);
    tmpstu.name = result[1];
    tmpstu.age = (int)std::stoi(result[2]);

    arry->emplace_back(std::move(tmpstu));
    //arry->push_back(result[0]);
    // for(int i = 0;i < col;i++){
        // arry->push_back(result[col]);
    // }
    return 0;
}

int main(){
    SqilteHelper test_sqlite("./test.db");
    assert(test_sqlite.open());

    const std::string order1 = "create table if not exists student(id int primary key,name varchar(16),age int)";
    assert(test_sqlite.exec(order1,nullptr,nullptr));

    // const std::string order2 = "insert into student values(123,'小雪',18),(456,'小新',18)";
    // assert(test_sqlite.exec(order2,nullptr,nullptr));

    const std::string order3 = "select * from student";
    std::vector<stu> arry;
    assert(test_sqlite.exec(order3,StuCallback,&arry));
    for(auto& e:arry){
        std::cout<<e.id<<" "<<e.name<<std::endl;
    }
    
    assert(test_sqlite.close());
    return 0;
}